<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of DaoObservacionFuncionario
 *
 * @author amartinez
 */
   include '../../../controlador/php/conexion/Conexion.php';
 
class ObservacionFuncionario {
    private $OidObservacion;
    private $Observacion;
    private $HistorialOid;
    
    function __construct($OidObservacion,$Observacion,$HistorialOid) {
        $this->OidObservacion = $OidObservacion;
        $this->Observacion = $Observacion;
        $this->HistorialOid = $HistorialOid;
    }
    
    function getOidObservacion(){
        return $this->OidObservacion;
    }
    
    function setOidObservacion($OidObservacion){
        $this->OidObservacion = $OidObservacion;
    }
    
    function getObservacion(){
        return $this->Observacion;
    }
    
    function setObservacion($Observacion){
        $this->Observacion = $Observacion;
    }
    
    function getHistorialOid(){
        return $this->HistorialOid;
    }
    
    function setHistorialOid($HistorialOid){
        $this->HistorialOid = $HistorialOid;
    }
    
    function GuardarObservacion(){
        
        $con = new Conexion();
        
        $Existe = "SELECT COUNT(*)AS N FROM DnObservacionCon_new WHERE HistorialOid = '".$this->HistorialOid."'";
        $res = $con ->query($Existe);
        
        while($res2 = mssql_fetch_array($res)){
            $N = $res2['N'];
        }
        
        if($N == 0){
           $GuardarObservacion = "INSERT INTO DnObservacionCon_new(Observacion,HistorialOid)VALUES('".$this->Observacion."','".$this->HistorialOid."')";
           $con ->query($GuardarObservacion); 
        }
        else if($N == 1){
           $EditarObservacion = "UPDATE DnObservacionCon_new
                                SET Observacion = '".$this->Observacion."'
                                WHERE HistorialOid = '".$this->HistorialOid."'";
           $con ->query($EditarObservacion); 
        }
        
        $con ->cerrarConexion();
    }
    
    function ConsultarObservacion($OidSolicitud){
        $con = new Conexion();
        
        
       $ConsultarObservacion ="SELECT OBS.Oid,CAST(Observacion AS TEXT)AS Observacion,HistorialOid,EST.GeNombe,H.Hssfecha
                                FROM DnObservacionCon_new AS OBS
                                     LEFT OUTER JOIN DnHistorialSs_new AS H ON OBS.HistorialOid = H.Oid
                                     LEFT OUTER JOIN GrlEstado_new AS EST ON H.EstadoOid = EST.Oid
                                WHERE SsOid = '".$OidSolicitud."'";
      $res =  $con ->query($ConsultarObservacion);
        
       while($res2 = mssql_fetch_array($res)){
            
           $lista[] = array_map(utf8_encode, $res2);
            
       }
        
        print_r(json_encode($lista));
        $con ->cerrarConexion();
    }
    
}

?>
